package com.liujun.spring4.demo.aop.application.property.crypto;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * @author liujun
 * @version 0.0.1
 * @date 2018/09/06
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

  private String[] encryptproName = {"userName", "password"};

  @Override
  protected String convertProperty(String propertyName, String propertyValue) {

    if (isCheckDecrypt(propertyName)) {
      String decodeValue = DESUtils.getDecryptString(propertyValue);
      return decodeValue;
    }

    return propertyValue;
  }

  private boolean isCheckDecrypt(String propertyName) {
    for (String item : encryptproName) {
      if (item.equals(propertyName)) {
        return true;
      }
    }

    return false;
  }
}
